﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_IDAL;
using Zor_Modes;

namespace Zor_DAL
{
    public class Notice_DAL<T> where T : class
    {

        /// <summary>
        /// 获取 - 通知公告列表
        /// </summary>
        /// <returns></returns>
        public static List<T> GetNoticeList(int typeId)
        {
            var sql = "select * from [Information] where Info_Type='" + typeId + "'";
            List<T> lst = DapperQuery<T>.DoQueryList(sql, null);
            return lst;
        }

        /// <summary>
        /// 根据ID获取信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static M_Information GetT(int id)
        {
            var sql = "select * from [Information] where Info_Id=@Info_Id";
            M_Information mt = DapperQuery<M_Information>.DoQueryT(sql, new { Info_Id = id });
            return mt;
        }

        /// <summary>
        /// 新增 - 通知公告
        /// </summary>
        /// <param name="infomation"></param>
        /// <returns></returns>
        public static BaseAnswer AddNotice(M_Information infomation)
        {
            BaseAnswer ba = new BaseAnswer();
            var sql = "insert into Information values(@Info_Type,@Info_Title,@Info_Mation,@Info_Date,@Info_SubMation)";
            ba = DapperInsert<T>.DoInsert(sql, infomation);
            return ba;
        }

        /// <summary>
        /// 编辑 - 通知公告
        /// </summary>
        /// <param name="infomation"></param>
        /// <returns></returns>
        public static BaseAnswer EditNotice(M_Information infomation)
        {
            BaseAnswer bar = new BaseAnswer();
            var sql = "update Information set Info_Title=@Info_Title,Info_Mation=@Info_Mation,Info_Date=@Info_Date,Info_SubMation = @Info_SubMation where Info_Id=@Info_Id";
            bar = DapperEdit<T>.DoEdit(sql, infomation);
            return bar;
        }

        /// <summary>
        /// 删除 - 通知公告
        /// </summary>
        /// <param name="ids">唯一标识数组  </param>
        /// <returns></returns>
        public static BaseAnswer DeleteNotice(int[] ids)
        {
            BaseAnswer bar = new BaseAnswer();
            var sql = "delete from Information where Info_Id in @Info_Id";
            bar = DapperDelete<T>.DoDelete(sql, new { Info_Id = ids });
            return bar;
        }


    }
}
